package com.qingke.easyjava.jdbc.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class PropertyManager {

	private static Map<String,PropertyManager> instanceMap = new HashMap<>();
	
	private Properties props;
	
	private PropertyManager(String propsFile) {
		props = new Properties();
		try {
			props.load(new FileInputStream(propsFile));//加载propsFile下的健值对
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			throw new RuntimeException("Unable to load properties for the file:" + propsFile);
		}
	}
	
	public static synchronized PropertyManager getInstance(String propsFile) {
		PropertyManager instance = instanceMap.get(propsFile);
		if(instance == null) {
			instance = new PropertyManager(propsFile);
			instanceMap.put(propsFile, instance);
		}
		return instance;
	}
	
	public String getProperty(String key) {
		return props.getProperty(key);
	}
	
	public String[] getPropertyList(String key) {
		return props.getProperty(key).split(",");//切分
	}
}
